<!DOCTYPE html>
<html>
  <head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="theme-color" content="hsl(35, 36%, 95%)">
  <title>Sleeping Beauty</title>

  
  <meta name="description" content="
  
    
      
        Sleeping Beauty
        28 May 2016
        
          
        
      
    
    
      
      
        
          
       ..." />

  
  <meta name="keywords" content="" />

  <link rel="canonical" href="http://hugosereno.euhttps://ymmuse.oschina.io/test/blog/2016/05/28/sleeping-beauty/">
  <link rel="alternate" type="application/rss+xml" title="On Software Engineering, Mathematics<br>and Philosophy" href="http://hugosereno.euhttps://ymmuse.oschina.io/test/feed.xml" />
  <span itemprop='author'><meta name="author" content="Hugo Sereno Ferreira"><span itemprop='author'></span>

  <link href="/favicon.png" rel="icon">
  <link rel="stylesheet" href="//brick.a.ssl.fastly.net/PT+Serif:400,400i,700,700i:f/Source+Code+Pro:400,600:f">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
  <link rel="stylesheet" href="https://ymmuse.oschina.io/test/css/main.css">
  <script type="text/javascript">
    window.MathJax = {
      tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"] ],
        displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
        processEscapes: true
      },

      TeX: {
        equationNumbers: { autoNumber: "AMS" }
      },

      CommonHTML: {
        scale: 90
      }
    };
}
  </script>
  <script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"></script>

  <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-69060-5', 'auto');
    ga('send', 'pageview');
  </script>
</head>

  <body>
    <div class="post">
  <div class="container main">
    <div class="row">
      <header>
        <center><span itemprop="name"><h1>Sleeping Beauty</h1></span></center>
        <center><p>28 May 2016</p></center>
        <center><span class="small-ornament"><svg viewBox="0 0 290 320">
          <path d="M280.2656 245.3906 Q280.2656 263.25 261.8438 271.9688 Q247.9219 278.7188 227.8125 278.7188 Q235.2656 269.8594 235.2656 256.5 Q235.2656 231.8906 214.4531 217.125 Q196.0312 204.0469 170.2969 204.0469 Q143.5781 204.0469 108.8438 221.0625 L118.9688 231.4688 Q154.4062 267.8906 168.3281 267.8906 Q181.125 267.8906 181.125 255.9375 Q181.125 248.3438 173.5312 243.5625 Q167.0625 239.3438 159.0469 239.3438 Q154.6875 239.3438 148.6406 241.4531 Q158.625 220.0781 173.9531 220.0781 Q184.5 220.0781 191.8828 228.0938 Q199.2656 236.1094 199.2656 246.6562 Q199.2656 265.5 184.3594 277.875 Q170.2969 289.4062 151.0312 289.4062 Q118.6875 289.4062 81.4219 251.0156 L72.1406 241.4531 Q53.5781 249.4688 39.375 249.4688 Q26.4375 249.4688 17.1562 240.9609 Q7.875 232.4531 7.875 219.5156 Q7.875 203.9062 19.125 193.9219 Q29.9531 184.5 45.8438 184.5 Q70.0312 184.5 98.2969 211.6406 Q111.5156 202.2188 127.5469 185.4844 L134.5781 178.1719 Q174.5156 136.6875 204.8906 136.6875 Q231.4688 136.6875 231.4688 155.25 Q231.4688 173.5312 204.3281 177.3281 Q206.4375 172.8281 206.4375 170.1562 Q206.4375 159.3281 193.3594 159.3281 Q175.2188 159.3281 144.2812 189 L137.1094 195.8906 Q165.2344 185.7656 191.25 185.7656 Q221.7656 185.7656 248.3438 200.1094 Q280.2656 217.2656 280.2656 245.3906 ZM61.1719 230.4844 Q44.5781 215.2969 37.2656 215.2969 Q27.9844 215.2969 27.9844 223.4531 Q27.9844 234.4219 42.75 234.4219 Q51.1875 234.4219 61.1719 230.4844z"/>
        </svg></span></center>
      </header>
    </div>
    <div class="row">
      <div class="col-md-1"></div>
      <div class="col-md-8 offset-md-1">
        <article lang="en">
          
          <blockquote>
  <p>Sleeping Beauty undergoes an experiment where she’s put to sleep on Sunday. Immediately after that, a fair coin is tossed. If it comes out Heads, Sleeping Beauty is waken on Monday. If it comes out Tails, she’s waken both on Monday and Tuesday. After being waken, the experimentalist asks Sleeping Beauty: <em>“What is your degree of certainty that the coin landed heads?”</em>. He subsequently puts Sleeping Beauty to sleep, taking care to administer her an amnesia inducing drug that ensures she doesn’t remember the experiment. Hence, everytime Sleeping Beauty is awaked, she won’t know which day it is or whether she has already been awakened before or not. What should her answer be?</p>
</blockquote>

<p>It’s amazing how a simple puzzle installs chaos among mathematicians and philosophers alike. Some would argue that the correct probability is ½: after all, the coin is <strong>fair</strong>, isn’t it? Others would say that the correct probability should be ⅓. Think about this problem for a second because the correct answer is… <strong>both</strong>!</p>

<p>As many things in life, it’s all a matter of perspective. And the conundrum here lies in the way the problem is phrased. But before going into maths and probability theory, we shall <strong>simulate</strong>:</p>

<div class="language-scala highlighter-rouge"><pre class="highlight"><code><span class="k">var</span> <span class="n">correct</span> <span class="k">=</span> <span class="mi">0</span>
<span class="k">var</span> <span class="n">questions</span> <span class="k">=</span> <span class="mi">0</span>
<span class="k">var</span> <span class="n">heads</span> <span class="k">=</span> <span class="mi">0</span>
<span class="k">var</span> <span class="n">trials</span> <span class="k">=</span> <span class="mi">10000</span>

<span class="c1">// Let's run some trials
</span><span class="o">(</span><span class="mi">1</span> <span class="n">to</span> <span class="n">trials</span><span class="o">).</span><span class="n">foreach</span> <span class="o">{</span> <span class="n">trial</span> <span class="k">=&gt;</span>
  <span class="c1">// toss a fair coin
</span>  <span class="n">scala</span><span class="o">.</span><span class="n">util</span><span class="o">.</span><span class="nc">Random</span><span class="o">.</span><span class="n">nextBoolean</span><span class="o">()</span> <span class="k">match</span> <span class="o">{</span>
    <span class="k">case</span> <span class="kc">true</span> <span class="k">=&gt;</span>  <span class="c1">// Heads was tossed. Wake on Monday.
</span>      <span class="c1">// Sleeping Beauty always bet Heads was tossed;
</span>      <span class="c1">// ... in this case, only once.
</span>      <span class="n">questions</span> <span class="o">+=</span> <span class="mi">1</span>
      <span class="n">correct</span> <span class="o">+=</span> <span class="mi">1</span>
      <span class="n">heads</span> <span class="o">+=</span> <span class="mi">1</span>
    <span class="k">case</span> <span class="k">_</span> <span class="k">=&gt;</span>     <span class="c1">// Tails was tossed. Wake on Monday and Tuesday.
</span>      <span class="c1">// Sleeping Beauty always bet Heads was tossed;
</span>      <span class="c1">// ... in this case, it will bet both on Monday
</span>      <span class="c1">// and Tuesday. But it will fail!
</span>      <span class="n">questions</span> <span class="o">+=</span> <span class="mi">2</span>
  <span class="o">}</span>
<span class="o">}</span>

<span class="n">println</span><span class="o">(</span><span class="s">"Probability of SB being correct: "</span> <span class="o">+</span> <span class="n">correct</span><span class="o">.</span><span class="n">toDouble</span><span class="o">/</span><span class="n">questions</span><span class="o">)</span>
<span class="n">println</span><span class="o">(</span><span class="s">"Probability of Heads being tossed: "</span> <span class="o">+</span> <span class="n">heads</span><span class="o">.</span><span class="n">toDouble</span><span class="o">/</span><span class="n">trials</span><span class="o">)</span>
</code></pre>
</div>

<p>Here’s a sample run:</p>

<div class="highlighter-rouge"><pre class="highlight"><code>Probability of SB being correct: 0.33636242148870776
Probability of Heads being tossed: 0.5034
</code></pre>
</div>

<h2 id="two-questions-two-answers">Two questions, two answers</h2>

<p>The attentive reader should have already grasped that the answer depends on <em>what exactly we are counting as a success</em>. If we measure success as the <em>number of times Sleeping Beauty is able to give a correct answer</em>, then her <em>degree</em> of confidence should be ⅓, as the above simulation shows. If you are still unable to see how, under that measurement of success, the number of times Sleeping Beauty is awakened impacts the answer, then imagine the following puzzle variant:</p>

<blockquote>
  <p>(…) she’s put to sleep on the 31th of December. If it comes out Heads, Sleeping Beauty is waken on the 1st of January. If it comes out Tails, she’s waken every single day for the whole year, <em>i.e.</em>, 365 days.</p>
</blockquote>

<p>Or even something a little more extreme:</p>

<blockquote>
  <p>(…) If it comes out Heads, Sleeping Beauty is waken on Monday. If it comes out Tails, she stays asleep forever.</p>
</blockquote>

<p>The last one is my favorite variation, since it’s pretty obvious that, if she’s ever awakened, then the confidence she has that Heads was tossed is 100%; even if that mere fact doesn’t influence even a bit the tossing of a fair coin. It is an <em>a posteriori</em> confidence, <em>given that she’s waken</em>.</p>

<p>On the converse, this discussion points out to the second interpretation, which is the <em>confidence Sleeping Beauty has that the coin could produce Heads at the moment of tossing</em>. In other words, an <em>a priori</em> confidence on the bias of the coin <em>per se</em>. This last one would always be 0.5, but we can no longer rely on multiple trials to measure success(es) because if Tails come up, Sleeping Beauty will never be able to answer.</p>

<p>There has been an extensive discussion on this topic, so I will not reiterate what has already been well laid out <a href="http://arxiv.org/ftp/arxiv/papers/0806/0806.1316.pdf">in this paper</a>, in this  <a href="https://www.youtube.com/watch?v=zL52lG6aNIY">video</a>, in <a href="https://en.wikipedia.org/wiki/Sleeping_Beauty">Wikipedia</a>, or, more recently, during several different expositions [<a href="https://www.quantamagazine.org/20160114-sleeping-beautys-necker-cube-dilemma/">1</a>,
<a href="https://www.quantamagazine.org/20160129-solution-sleeping-beautys-dilemma/">2</a>, <a href="https://www.quantamagazine.org/20160331-why-sleeping-beauty-is-lost-in-time/">3</a>] in <a href="http://www.quantamagazine.org/">Quanta Magazine</a>.</p>

        </article>
        
        <div class="row">
        <!-- 多说评论框 start -->
          <div class="ds-thread" data-thread-key="http://hugosereno.eu/blog/2016/05/28/sleeping-beauty" data-title="Sleeping Beauty" data-url="http://hugosereno.eu/blog/2016/05/28/sleeping-beauty"></div>
        <!-- 多说评论框 end -->
        <!-- 多说公共JS代码 start (一个网页只需插入一次) -->
        <script type="text/javascript">
        var duoshuoQuery = {short_name:"thinkingland"};
          (function() {
            var ds = document.createElement('script');
            ds.type = 'text/javascript';ds.async = true;
            ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
            ds.charset = 'UTF-8';
            (document.getElementsByTagName('head')[0] 
            || document.getElementsByTagName('body')[0]).appendChild(ds);
          })();
          </script>
        <!-- 多说公共JS代码 end -->
        </div>

	     </div>
     </div>
     

  </div>
</div>

    <footer>
  <div class="container">
    <div class="row biography">
      <div class="col-sm-4">
        <h2>who am i</h2>
        <p>I am a Professor of Software Engineering at the <a href='http://www.fe.up.pt'>Faculty of Engineering</a>, University of Porto and Senior Researcher at <a href='https://www.inesctec.pt'>INESC TEC</a>. Here you can find my <a href='/assets/thesis.pdf'>PhD Thesis</a> and my <a href='/assets/cv.pdf'>Résumé</a>.</p>
      </div>
      <div class="col-sm-4">
        <h2>what is this</h2>
        <p>This is a blog about software, some mathematics, and the occasional philosophy. Not necessarily in that order.</p>
      </div>
      <div class="col-sm-4">
        <h2>where am i</h2>
          
          
          <div>
            <a href="https://github.com/hugoferreira">
              <span class="username">github//hugoferreira</span>
            </a>
          </div>
          
          
          <div>
            <a href="https://twitter.com/ferreira_hugo">
              <span class="username">twitter//ferreira_hugo</span>
            </a>
          </div>
          
          
          <div>
            <a href="https://id.linkedin.com/in/hugoserenoferreira">
              <span class="username">linkedin//hugoserenoferreira</span>
            </a>
          </div>
          
          
          <div>
            <a href="https://www.facebook.com/hugo.sereno.ferreira">
              <span class="username">facebook//hugo.sereno.ferreira</span>
            </a>
          </div>
          
      </div>
    </div>
    
    <div class="row copyright">
      <center>© MMXIII — MMXVI by Hugo Sereno Ferreira.<br>Content available under <a href='http://creativecommons.org/licenses/by-nc-sa/4.0/'>Creative Commons (BY-NC-SA)</a> unless otherwise noted.<br>This site is hosted at <a href='https://pages.github.com/'>Github Pages</a> and created with <a href='http://jekyllrb.com/'>Jekyll</a>.</center>
    </div>
    
  </div>
</footer>

  </body>
</html>
